<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:x="http://www.loukianov.com/x2"
 xmlns:xhtml="http://www.w3.org/1999/xhtml"
 xmlns="http://www.w3.org/1999/xhtml"
 exclude-result-prefixes="xsl x xhtml">

<xsl:template match="x:doc" mode="x:css">
  <xsl:apply-imports/>
  <link rel="stylesheet" type="text/css" href="/~x2/ui/ui.css"/>
</xsl:template>

<!--  -->
<xsl:template match="x:doc[x:user/@status='4']" mode="x:toolbar-js">
  <script type="text/javascript" src="/~x2/scripts/utils.js"/>
  <script type="text/javascript" src="/~x2/scripts/HTTPRequest.js"/>
  <script type="text/javascript" src="/~x2/scripts/doc-dispatcher.js"/>
  <script type="text/javascript" src="/~x2/fckeditor/fckeditor.js" charset="utf-8"/>
  <script type="text/javascript">
var __TD = new TreeDispatcher(<xsl:value-of select="$current-id"/>);

function SetUrl(url){
  document.getElementById('thumbnail').value = url;
}
</script>
</xsl:template>

<xsl:template match="x:doc[x:user/@status='4']" mode="x:toolbar"><!--  -->
  <div id="x2-window-shadow">
    <iframe name="x2-window-shadow" src="/~x2/gate/doc-actions.php" width="1" height="1" frameborder="0"></iframe>
  </div>
  <div id="x2-toolbar">
    <form target="x2-window-shadow" action="/~x2/gate/doc-actions.php" onsubmit="return false;">
      <input type="hidden" name="id" value="{@id}"/>
      <input type="hidden" name="action" value="set-state"/>
      <input type="hidden" name="state">
        <xsl:attribute name="value">
          <xsl:choose>
            <xsl:when test="@state = 'published'">draft</xsl:when>
            <xsl:when test="@state = 'draft'">published</xsl:when>
            <xsl:otherwise>draft</xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>
      </input>
      <button id="x2-create-doc" title="Создать новый документ" onclick="__TD.createDoc()" onfocus="this.blur()"/>
      <button id="x2-attr-doc" title="Редактировать свойства документа" onclick="__TD.updateDoc()" onfocus="this.blur()"/>
      <button id="x2-edit-doc" title="Редактировать содержимое документа" onclick="__TD.editDoc()" onfocus="this.blur()"/>
      <button id="x2-delete-doc" title="Удалить документ" onclick="__TD.deleteDoc('{@uri}')" onfocus="this.blur()"/>
      <button id="x2-switch-state" class="on" title="Скрыть/показать документ" onclick="__TD.switchState()" onfocus="this.blur()">
        <xsl:attribute name="class">
          <xsl:choose>
            <xsl:when test="@state = 'published'">on</xsl:when>
            <xsl:when test="@state = 'draft'">off</xsl:when>
            <xsl:otherwise>off</xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>
      </button>
      <button id="x2-upload-file" title="Загрузить файл на сервер" onclick="__TD.uploadFile()" onfocus="this.blur()"/>
      <button id="x2-exit" title="Выйти" onclick="__TD.logout()" onfocus="this.blur()"/>
    </form>
  </div>
  <div id="x2-doc-info-top"/>
  <div id="x2-doc-info">
    <form name="x2-doc-info-form" action="/~x2/gate/tree-actions.php" method="post" target="x2-window-shadow">
      <input type="hidden" name="action" value="update"/>
      <input type="hidden" name="docId" value="{@id}"/>
      <input type="hidden" name="pos" value="{@position}"/>
      <input type="hidden" name="state" value="{@state}"/>
      <input type="hidden" name="parent" value="{../@uri}"/>
      <table cellspacing="0" width="100%">
        <tr>
          <td title="Название документа" width="30%">
            <label for="title">Название документа</label>
          </td>
          <td width="70%">
            <input type="text" name="title" id="title" value="{x:title}"/>
          </td>
        </tr>
        <tr>
          <td title="Адрес (URL)">
            <label for="url">Адрес (URL)</label>
          </td>
          <td>
            <input type="text" name="url" id="url" value="{@uri}" readonly="readonly"/>
          </td>
        </tr>
        <tr>
          <td>
            <label for="description">Описание</label>
          </td>
          <td>
            <textarea cols="20" rows="4" name="description" id="description">
              <xsl:copy-of select="x:description/node()"/>
            </textarea>
                <script type="text/javascript">
/*if(window.FCKeditor){
  var dFCKeditor = new FCKeditor('description');
  dFCKeditor.ToolbarSet = "Description";
  dFCKeditor.Height = '160px';
  dFCKeditor.Config.ToolbarStartExpanded = false;
  dFCKeditor.ReplaceTextarea();
}*/
</script>
          </td>
        </tr>
        <tr>
          <td title="Ключевые слова">
            <label for="keywords">Ключевые слова</label>
          </td>
          <td>
            <textarea cols="20" rows="4" name="keywords" id="keywords">
              <xsl:value-of select="x:keywords/node()"/>
            </textarea>
          </td>
        </tr>
        <tr>
          <td title="Тип содержимого">
            <label for="type">Тип содержимого</label>
          </td>
          <td>
            <select name="type" id="type">
              <xsl:for-each select="x:content-types/x:type">
                <option value="{@id}">
                  <xsl:if test="@id = ../../@type">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="@name"/>
                </option>
              </xsl:for-each>
            </select>
          </td>
        </tr>
        <tr>
          <td title="Иллюстрация к документу">
            <label for="thumbnail">Иллюстрация</label>
          </td>
          <td>
            <input type="text" style="width: 20em" name="thumbnail" id="thumbnail" value="{x:thumbnail}"/>
            <input type="button" style="width: 6em" value="Выбрать" onclick="__TD.uploadFile('Image')"/>
          </td>
        </tr>
        <tr>
          <td title="Показывать в оглавлениях">
            <label for="visible">Показывать в&#160;оглавлениях</label>
          </td>
          <td>
            <input type="checkbox" class="auto" name="visible" id="visible" value="{@visible}">
              <xsl:if test="@visible = 'yes'">
                <xsl:attribute name="checked">checked</xsl:attribute>
              </xsl:if>
            </input>
          </td>
        </tr>
        <tr>
          <td/>
          <td>
            <input type="submit" class="auto" value="Сохранить"/>
            <input type="button" class="auto" value="Отмена" onclick="__TD.hideAll();"/>
          </td>
        </tr>
      </table>
    </form>
  </div>

  <div id="x2-doc-delete">
    <form target="x2-window-shadow" action="/~x2/gate/doc-actions.php" onsubmit="return false;">
      <p>Вы уверены, что хотите удалить документ «<xsl:value-of select="x:title"/>»?</p>
      <p align="center">
        <input type="submit" class="auto" value="Сохранить"/>
        <input type="button" class="auto" value="Отмена" onclick="__TD.hideAll();"/>
      </p>
    </form>
  </div>

  <div id="x2-field-editor">
    <form id="x2-field-editor-form" target="x2-window-shadow" action="/~x2/gate/doc-actions.php" method="post" onsubmit="x2OnSaveField(this, 'markup')">
      <input type="hidden" name="action" value="save"/>
      <input type="hidden" name="id" value="{@id}"/>
      <input type="hidden" name="origId" value="{@id}"/>
      <input type="hidden" name="name" value=""/>
      <textarea name="markup" id="x2-field-editor-markup" rows="10" cols="64"></textarea>
      <script type="text/javascript">
if(window.FCKeditor){
  var markupEditor = new FCKeditor('markup');
  markupEditor.ToolbarSet = "Editor";
  markupEditor.Config.ToolbarStartExpanded = false;
  markupEditor.ReplaceTextarea();
}
function x2OnSaveField(form, editorId){
  var e = FCKeditorAPI.GetInstance(editorId);
  form.elements['markup'].value = e.GetXHTML(true);
}
</script>
  <div id="x2-field-editor-btns">
    <input type="submit" value="Сохранить"/>
  </div>
</form>
  </div>

  <div id="x2-debug-top"/>
  <div id="x2-debug">
    <form target="x2-window-shadow" action="/~x2/gate/doc-actions.php" onsubmit="return false">
      <div>
        <textarea id="x2-debug-info" name="debug-info" rows="20" cols="64"></textarea>
      </div>
      <div id="x2-field-editor-btns">
        <input type="button" value="Отмена" onclick="__TD.hideAll()"/>
      </div>
    </form>
  </div>
</xsl:template>

<xsl:template match="x:field[@editable = '1']">
  <div class="x2-field">
    <form target="x2-window-shadow" action="/~x2/gate/doc-actions.php" onsubmit="return false;">
      <button class="x2-edit-block" title="Редактировать содержимое блока" onclick="__TD.editField('{$x:doc/@id}', '{@origId}', 'x2-field-{@id}', '{@id}')" onfocus="this.blur()"/>
    </form>
    <div class="x2-field-container" id="x2-field-{@id}">
      <xsl:apply-imports/>
    </div>
  </div>
</xsl:template>

</xsl:stylesheet>